package com.guli.mall.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/*
 * @Author 罗
 * @date 2020/10/14 - 7:43 下午
 */
//@Controller
public class DispatchController {

    @GetMapping("list.html")
    public String toList(HttpServletRequest request) {
        /**
         * 获取到 @RequestParams 但是获取到的中文字符没有编码
         * */
        String queryString = request.getQueryString();

        /**编码中文字符
         * 浏览器的编码和java的不一样
         * 但是 url中的空格(%20)会被编码成 +
         */
        if(!StringUtils.isEmpty(queryString)) {
            try {
                String encode = URLEncoder.encode(queryString, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return "list";

    }
}
